/**
 * Created by zhanglihe on 15/10/30.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'template',
    'collection',
    'model',
    'dialog'
], function ($, common, ready, template, Collection, Model, dialog) {
    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            loading();
            this.fetch();
        },

        fetch: function (_args) {
            var _this = this;
            this.collection = new Collection({
                container: 'data-list',
                template: 'data-item',
                url: _global.url.api + 'hot_keywords',
                model: {
                    tag_name: 'tr',
                    url: {
                        put: _global.url.api + 'hot_keyword/{id}'
                    },
                    event: {
                        '.item-online:click': 'online',
                        '.item-offline:click': 'offline'
                    },
                    online: function (e) {
                        e.preventDefault();
                        this.data.is_visible = 1;
                        this.formData = {is_visible: 1};
                        this.put();
                    },
                    offline: function (e) {
                        e.preventDefault();
                        this.data.is_visible = 0;
                        this.formData = {is_visible: 0};
                        this.put();
                    }
                },
                callback: function () {
                    loaded();
                }
            });
            this.collection.fetch();
        }
    };

    new index();
});